#!/bin/sh

# Script for calculation 
# block circuts indexes in registers 30016-30024
#ATTENTION:  I think it not work correctly - strange indexes generate.

typeset -l to_file=$3
typeset -i from_index=$1 to_index=$2 registr_of_index=0 
typeset -i registr_length=16 bits_per_block_circut=2
typeset -i block_circuts_id_registr=registr_length/bits_per_block_circut
typeset -i begin_position_in_registr  end_position_in_registr

echo \\nindex\\tregistr\\tpos_in_byte\\n >> $to_file;

while test $from_index -le $to_index; do

    let registr_of_index=from_index/block_circuts_id_registr
    
    let begin_position_in_registr=from_index%block_circuts_id_registr+1
    let begin_position_in_registr=begin_position_in_registr*2
    let begin_position_in_registr=16-begin_position_in_registr

    let end_position_in_registr=begin_position_in_registr+bits_per_block_circut-1

    echo "$from_index\\t$registr_of_index\\t$begin_position_in_registr-$end_position_in_registr" >> $to_file;

    let from_index=from_index+1
done 

unset from_index to_index registr_of_index registr_length
unset bits_per_block_circut block_circuts_id_registr
unset begin_position_in_registr